package com.donkey.sms;

import com.cloopen.rest.sdk.CCPRestSmsSDK;

import java.util.Map;

/**
 * 容联运短信
 */
public class RongLianYun {

    public static void main(String[] args) {
        send();
    }

    static final String serverIp = "app.cloopen.com";
    static final String serverPort = "8883";
    static final String appId = "appId";
    static final String accountSid = "accountSid";
    static final String accountToken = "accountToken";

    static String to = "18905950XXX";
    static String templateId = "230426";
    static String[] argus = new String[]{"hello"};

    static void send() {
        // 初始化SDK
        CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
        restAPI.init(serverIp, serverPort);
        restAPI.setAppId(appId);
        restAPI.setAccount(accountSid, accountToken);
        // 获取发送参数
        Map<String, Object> result = restAPI.sendTemplateSMS(to, templateId, argus);

        if ("000000".equals(result.get("statusCode"))) {
            System.out.println("success");
        } else {
            System.out.println("failure");
        }
        System.out.println(result);
        // {
        // data={templateSMS={dateCreated=20180131122550, smsMessageSid=810f8b499b194eb0bfe2278759fc9527}},
        // statusCode=000000
        // }
        // {statusMsg=号码格式有误, statusCode=160042}
        // {statusMsg=短信模板无效, statusCode=160032}
    }
}
